﻿using MailBox.App_Code;
using MailBox.App_Code.dto;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MailBox
{
    public class Result
    {
        public string Signature { get; set; }
        public bool IsUse_S { get; set; }
        public string AutoReply { get; set; }
        public bool IsUse_R { get; set; }
    }
    public partial class Setting : Page
    {
        DataUtils data = new DataUtils();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public static Result LoadData()
        {
            UserLoginDTO user = (UserLoginDTO)HttpContext.Current.Session["UserLogin"];
            DataUtils data = new DataUtils();
            DataTable t = data.GetSignatureAndAutoReplyByAccountID(user.Account.AccountID);
            Result r = new Result();
            if (t != null && t.Rows.Count > 0)
            {
                r.Signature = t.Rows[0]["signature"] + "";
                r.IsUse_S = Convert.ToBoolean(t.Rows[0]["isuse_s"] + "");
                r.AutoReply = t.Rows[0]["autoreply"] + "";
                r.IsUse_R = Convert.ToBoolean(t.Rows[0]["isuse_r"] + "");
            }
            return r;
        }
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public static void SaveSignature(string signature, int isuse)
        {
            UserLoginDTO user = (UserLoginDTO)HttpContext.Current.Session["UserLogin"];
            DataUtils data = new DataUtils();
            data.SaveSignature(signature, isuse, user.Account.AccountID);
        }
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public static void Saveautoreply(string autoreply, int isuse)
        {
            UserLoginDTO user = (UserLoginDTO)HttpContext.Current.Session["UserLogin"];
            DataUtils data = new DataUtils();
            data.SaveAutoReply(autoreply, isuse, user.Account.AccountID);
        }
    }
}